#include <my_header.h>
#include "Stack.h"


void stackInit(Stack * s){
    s->str = (char**)calloc(INIT_CAPCITY,sizeof(char*));
    s->size = 0;
    s->capacity = INIT_CAPCITY;
    s->top = -1;
}

void push(Stack * s,char * p){
    if(s->size == s->capacity){
        s->str = (char**)realloc(s->str,2 * s->size *sizeof(char*));
        s->capacity = s->size * 2;
    }
    ++s->top;
    s->str[s->top] = p;
    ++s->size;
}

void pop(Stack * s){
    if(s->size == 0){
        return ;
    }    
    --s->top;
    --s->size;
}

char* top(Stack * s){
    return s->str[s->top];
}


bool isEmpty(Stack * s){
    if(s->size == 0){
        return true;
    }
    return false;
}

void destroyStack(Stack * s){
    while(!isEmpty(s)){
        free(top(s));
        pop(s);
    }
}





